package Tools;

/**
 * Lock down the current thread.  To wake it back up, a separate thread must call this class's Release method
 * 
 * This class should almost never be used for real implementation
 * If an object is destroyed by the garbage collector, it will
 * not be possible to retrieve its lock.
 * The thread that is waiting will be deadlocked.
 * Use for testing purposes only.
 * @author jeffrey
 *
 */
public class Lock {

	public static Object lock = new Object();
	
	/**
	 * Locks the thread that invoked this method
	 */
	public static void Lock()
	{
		synchronized(lock)
		{
			try {
				lock.wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * Releases the original thread that used this lock
	 */
	public static void Release()
	{
		synchronized(lock)
		{
			lock.notifyAll();
		}
	}
	
}
